package linker;

import java.io.FileOutputStream;
import java.util.HashMap;

import att.grappa.Edge;
import att.grappa.Graph;
import att.grappa.Node;
import edu.mit.jwi.item.ISynset;

public class DotExport {
	private HashMap<ISynset,Node> done;
	static private int counter=0;
	private Graph tree;
	public DotExport() {
		done= new HashMap<ISynset,Node>();
		tree= new Graph("hypernym tree",false,false);
	}
	

	
	public void add(ISynset f,ISynset s){

		Node h;
		Node t;
		Edge e;
		if(!done.containsKey(f))
		{ 
			h = new Node(tree,counter+": "+makeSurfix1(f.getWord(1).toString()));
			done.put(f,h);
			counter++;
			tree.addNode(h);
		}
		else
			h=done.get(f);
		if(!done.containsKey(s))
		{
			t = new Node(tree,counter+": "+makeSurfix1(s.getWord(1).toString()));
			done.put(s,t);
			counter++;
			tree.addNode(t);
		}
		else
			t=done.get(s);
		e= new Edge(tree, h,t);
		tree.addEdge(e);
	}
	public void export(FileOutputStream out)
	{
		tree.printGraph(out);
	}
	private String makeSurfix1(String id) {
		String[] rets=id.split("-");
		return rets[rets.length-1];
	}
}